import React from 'react';
import styles from './index.less';
import { Button, Form, Input, message } from 'antd';
import { history } from 'umi';

window.registerEvent?.('alertWebMsg', (arg) => {
  message[arg.type || 'info'](arg.text);
});

window.registerEvent?.('handle_jump', (arg) => {
  history.push(arg.path);
});

window.registerEvent?.('console_log', (...arg) => {
  console.log('> main:', ...arg);
});

export default function IndexPage() {
  const [form] = Form.useForm();

  const onSubmit = () => {
    form.validateFields().then((values) => {
      window.useElectronApi?.alertSysMsg?.(values);
    });
  };

  return (
    <div className={styles.container}>
      <Form form={form}>
        <Form.Item name={'title'} initialValue={'hello'}>
          <Input />
        </Form.Item>
        <Form.Item name={'body'} initialValue={'I am web'}>
          <Input />
        </Form.Item>
        <Button type="primary" onClick={onSubmit}>
          Submit
        </Button>
      </Form>
    </div>
  );
}
